package com.i.template.service.impl;

import cn.hutool.core.map.MapBuilder;
import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.i.template.domain.MusicDO;
import com.i.template.mapper.MusicMapper;
import com.i.template.service.IMusicService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * @author lewis
 * @type class
 * @description
 * @since 2024/8/2
 */
@Service
@RequiredArgsConstructor
public class MusicServiceImpl extends ServiceImpl<MusicMapper, MusicDO> implements IMusicService {
    private final MusicMapper mapper;
    @Override
//    @Transactional
    public Boolean saveMusic(MusicDO musicDO) {
        return save(musicDO);
//        MusicDO one = lambdaQuery().eq(MusicDO::getMusicName, musicDO.getMusicName()).one();
//        return mapper.saveMusicToPlayList(one);
    }

    @Override
    public Boolean saveMusicToList(Long userId,Long musicId) {
        Map<String,Long> map = MapBuilder
                .create(new HashMap<String,Long>())
                .put("userId",userId)
                .put("musicId",musicId)
                .map();
        return mapper.saveMusicToList(map);
    }

    @Override
    public List<MusicDO> queryMusicListByUserId(Long id) {
        return mapper.queryMusicListByUserId(id);
    }
}
